﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;

[DisallowMultipleComponent]
/// <summary>
/// UI游戏物体点击缩放效果
/// </summary>
public class UIClickScaleEffect : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [Header("被控制的游戏体")]
    public GameObject TargetGo;

    [Header("常态缩放数据")]
    public float NormalScaleValue = 1;
    public float NormalScaleTime = 0.05f;

    [Header("选择缩放数据")]
    public float SelectScaleValue = 0.95f;
    public float SelectScaleTime = 0.05f;

    Vector3 _Scale;

    private void OnValidate()
    {
        if(TargetGo == null)
        {
            TargetGo = gameObject;
        }
    }

    private void Awake()
    {
        InitEffect();
    }

    private void InitEffect()
    {
        _Scale = CurrentScale;
    }

    #region component event

    public void OnPointerDown(PointerEventData eventData)
    {
        if (TargetGo == null)
            return;
        TargetGo.transform.DOScale(_Scale * SelectScaleValue, SelectScaleTime);
        TargetGo.transform.DOScale(_Scale * NormalScaleValue, NormalScaleTime).SetDelay(SelectScaleTime);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (TargetGo == null)
            return;
        //TargetGo.transform.DOScale(_Scale * NormalScaleValue, NormalScaleTime);
    }

    #endregion

    #region attribute

    public Vector3 CurrentScale
    {
        get
        {
            if (TargetGo == null)
            {
                return Vector3.one;
            }
            return TargetGo.transform.localScale;
        }
    }

    #endregion
}
